GBML manual / Language

What GBML is

An event-driven scripting language for the Game Boy Advance, compiled ahead of time to C++.

An event-driven language, for this engine

GBML is Gbabel's own scripting language, shaped around objects, instances and events: you write small pieces of code that each answer one question ("what happens when this is created", "what happens every frame", "what happens when this alarm goes off"), attach them to an object, and the engine calls the right one at the right moment. You never write a main loop, and you never poll for what happened - you describe what an object does when something happens to it, and the frame order (The order of a frame) takes care of calling it.

The vocabulary is this engine's own: instance_create(x, y, obj_thing), not a class constructor; buttons (BTN_A, BTN_L), not a keyboard; instances, not layers.

Compiled, not interpreted

A GBML file is compiled ahead of time into C++, then linked against the engine and built into a ROM with everything else. Nothing in a shipped game is interpreted at run time. The C++ a script compiles to sits right next to hand-written engine code, at the same speed.

// objects/obj_pickup_coin/create.gbml
bob_phase = 0;         // real, 0..360 - how far around its bob cycle this coin is
value     = 1;
// objects/obj_pickup_coin/step.gbml
bob_phase += 4;
if (bob_phase >= 360) { bob_phase -= 360; }

Roughly, the second file compiles to something like:

void obj_pickup_coin_step(obj_pickup_coin& self)
{
    self.bob_phase += 4;
    if(self.bob_phase >= 360) { self.bob_phase -= 360; }
}

with a #line directive above it pointing back at step.gbml's own line 1 - so a mistake here still shows up as an error in your file, at the line you wrote, never in generated C++ you never open. The same mapping is what lets the editor jump straight to the right event when you middle-click a compiler error.

Statically typed, by inference

You do not write type annotations on every variable. GBML decides a variable's type from what you first assign it, from the API table when you call a built-in, and - only where it genuinely cannot tell - from a short /// documentation comment you add. See Variables, types and scope for the rules in full; the short version is that a variable has exactly one type for its whole life, decided once, which is also exactly what its generated C++ field needs to be true.

Every refusal explains itself

When something does not compile, GBML does not print a bare error code. Every message names the exact file and line, says what is wrong in plain language, and says what to do about it:

objects/obj_pickup_coin/step.gbml:2:5
  `bob_phase` was a real (line 2 of create.gbml) and is now compared against an int literal.
  This is fine - int compares against real - but double check 360 was meant as a real here.

(a made-up example, not a real message from a build) These pages quote only the sentence. In the editor, each message also ends with a small, quiet label: the message's reference code. You never need it to fix the problem. It is there so you can quote it when you ask someone for help. Plain words, the exact place and what to do about it are the standard every message holds itself to, not just the friendly ones - see What is unavailable, and why for what happens when you reach for something the hardware genuinely cannot do.

One table, five consumers

Everything GBML can call - every function, variable, constant and event - is declared exactly once, in the API table (gbml/api/*.js). The checker, the code generator, completion and hover, the drag-and-drop block palette, and this manual all read that same table. A function that is listed as unavailable (support: 'none') still has an entry and still has a manual page, so the compiler can tell you why it does not exist instead of just "unknown function" - see What is unavailable, and why.

Where to go next

See also: Variables, types and scopeObjects and instancesEventsWhat is unavailable, and why